<?php

namespace LowCode\Support;

use LowCode\Abstracts\JsBase;

/**
 * JsLibs
 * @method static static make(bool $isFunction = true)
 */
class JsLibs extends JsBase
{
    protected string $libs = "this.\$libs";

    /**
     * @param bool $isFunction 是否函数包裹
     */
    public function __construct(bool $isFunction = true){
        $this->libs = Js::libs();
        $this->setJsFunction($isFunction);
    }

    public static function getRequest(): string
    {
        return Js::libs("\$request");
    }

    public static function getRouter(): string
    {
        return Js::libs("\$router");
    }

    public static function useUserStore(): string
    {
        return Js::libs("useUserStore()");
    }

    public static function getUserInfo(string $key = ""): string
    {
        $store = self::useUserStore();
        if ($key){
            $script = "{$store}.userInfo.{$key}";
        }else{
            $script = "{$store}.userInfo";
        }
        return $script;
    }
}
